package com.cdtu.stocksage.goods.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdtu.stocksage.common.annotation.Log;
import com.cdtu.stocksage.common.core.controller.BaseController;
import com.cdtu.stocksage.common.core.domain.AjaxResult;
import com.cdtu.stocksage.common.enums.BusinessType;
import com.cdtu.stocksage.goods.domain.ErsGoodsOutDetail;
import com.cdtu.stocksage.goods.service.IErsGoodsOutDetailService;
import com.cdtu.stocksage.common.utils.poi.ExcelUtil;
import com.cdtu.stocksage.common.core.page.TableDataInfo;

/**
 * 物资出库明细Controller
 * 
 * @author SL
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/goods/detail")
public class ErsGoodsOutDetailController extends BaseController
{
    @Autowired
    private IErsGoodsOutDetailService ersGoodsOutDetailService;

    /**
     * 查询物资出库明细列表
     */
    @PreAuthorize("@ss.hasPermi('goods:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErsGoodsOutDetail ersGoodsOutDetail)
    {
        startPage();
        List<ErsGoodsOutDetail> list = ersGoodsOutDetailService.selectErsGoodsOutDetailList(ersGoodsOutDetail);
        return getDataTable(list);
    }

    /**
     * 导出物资出库明细列表
     */
    @PreAuthorize("@ss.hasPermi('goods:detail:export')")
    @Log(title = "物资出库明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErsGoodsOutDetail ersGoodsOutDetail)
    {
        List<ErsGoodsOutDetail> list = ersGoodsOutDetailService.selectErsGoodsOutDetailList(ersGoodsOutDetail);
        ExcelUtil<ErsGoodsOutDetail> util = new ExcelUtil<ErsGoodsOutDetail>(ErsGoodsOutDetail.class);
        util.exportExcel(response, list, "物资出库明细数据");
    }

    /**
     * 获取物资出库明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ersGoodsOutDetailService.selectErsGoodsOutDetailById(id));
    }

    /**
     * 新增物资出库明细
     */
    @PreAuthorize("@ss.hasPermi('goods:detail:add')")
    @Log(title = "物资出库明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErsGoodsOutDetail ersGoodsOutDetail)
    {
        return toAjax(ersGoodsOutDetailService.insertErsGoodsOutDetail(ersGoodsOutDetail));
    }

    /**
     * 修改物资出库明细
     */
    @PreAuthorize("@ss.hasPermi('goods:detail:edit')")
    @Log(title = "物资出库明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErsGoodsOutDetail ersGoodsOutDetail)
    {
        return toAjax(ersGoodsOutDetailService.updateErsGoodsOutDetail(ersGoodsOutDetail));
    }

    /**
     * 删除物资出库明细
     */
    @PreAuthorize("@ss.hasPermi('goods:detail:remove')")
    @Log(title = "物资出库明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ersGoodsOutDetailService.deleteErsGoodsOutDetailByIds(ids));
    }
}
